<?php
namespace app\massage\controller;

use app\AdminRest;
use app\massage\model\GroupRatio;
use app\massage\model\User;
use app\massage\model\UserGroup;
use think\App;

class AdminGroup extends AdminRest
{
    protected $model;
    protected $user_model;
    protected $group_ratio_model;

    public function __construct(App $app) {
        parent::__construct($app);
        $this->model = new UserGroup();
        $this->user_model = new User();
        $this->group_ratio_model = new GroupRatio();
    }

    /**
     * @return \think\Response
     * 用户组列表
     */
    public function dataList()
    {
        $dis = ['status' => 1];
        $data = $this->model->dataList($dis);
        return $this->success($data);
    }

    /**
     * @return \think\Response
     * 用户组列表
     */
    public function list()
    {
        $input = $this->_param;
        $dis = [];
        $data = $this->model->list($dis,$input['limit']);
        return $this->success($data);
    }

    /**
     * @return \think\Response
     * 添加用户组
     */
    public function groupAdd()
    {
        $input = $this->_param;
        $res = $this->model->dataAdd($input);
        return $this->success($res);
    }

    /**
     * @return \think\Response
     * 编辑用户组
     */
    public function groupUpdate()
    {
        $input = $this->_param;
        $id = $input['id'];
        unset($input['id']);
        $res = $this->model->dataUpdate(['id' => $id],$input);
        return $this->success($res);
    }

    //设置分组
    public function setGroup()
    {
        $input = $this->_param;
        $res = $this->user_model->dataUpdate(['id' => $input['user_id']],['group_id' => $input['group_id']]);
        return $this->success($res);
    }

    //设置分组个人比例
    public function setGroupRatio()
    {
        $input = $this->_param;
        $res = $this->group_ratio_model->setRatio($input);
        return $this->success($res);
    }

    //用户组详情
    public function groupInfo()
    {
        $input = $this->_param;
        $data = $this->model->dataInfo(['id' => $input['id']]);
        $data['ratio'] = $this->group_ratio_model->dataList(['group_id' => $input['id']]);
        return $this->success($data);
    }
}
